package com.it.service.impl;

import com.it.dao.AccountDao;
import com.it.pojo.Account;
import com.it.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("accountService")
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }


    public void transferMoney(Integer inId, Integer outId, Float money) {
        /*
        根据id查用户
         */

        Account byInAccount = accountDao.findById(inId);
        System.out.println("byInAccount = " + byInAccount);
        Account byOutAccount = accountDao.findById(outId);
        System.out.println("byOutAccount = " + byOutAccount);

        /*
        根据id转进转出
         */
        accountDao.transferIn(inId,money);
        accountDao.transferOut(outId,money);
    }
}
